package mx.com.switz.peliculas.dao.impl;

import java.util.List;

import javax.sql.DataSource;

import mx.com.switz.peliculas.dao.SocioDao;
import mx.com.switz.peliculas.dto.Socio;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

@Repository
public class SocioDaoImpl extends JdbcDaoSupport implements SocioDao {

	private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
	@Autowired
	public SocioDaoImpl(DataSource dataSource){
		setDataSource(dataSource);
		this.namedParameterJdbcTemplate= new NamedParameterJdbcTemplate(dataSource);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Socio selectUserById(int id) {
		// TODO Auto-generated method stub
		String query = "SELECT * from socio where id=?";
		try{
		 return getJdbcTemplate().queryForObject(
					query, new Object[] { id }, 
					new BeanPropertyRowMapper(Socio.class));
		
		}catch(Exception e){
			return null;
		}
		
	}

}
